//
//  LoginViewController.m
//  LockTest
//
//  Created by ZhangBo on 2018/12/12.
//  Copyright © 2018 ZhangBo. All rights reserved.
//

#import "LoginViewController.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import "LoginViewModel.h"

@interface LoginViewController ()
@property(weak, nonatomic) IBOutlet UITextField *accountFiled;
@property(weak, nonatomic) IBOutlet UITextField *pwdFiled;
@property(weak, nonatomic) IBOutlet UIButton *loginBtn;

/** VM  */
@property(nonatomic, strong) LoginViewModel *loginVM;

@end

@implementation LoginViewController

- (LoginViewModel *)loginVM {
    //有效避免出错!!
    if (nil == _loginVM) {
        _loginVM = [[LoginViewModel alloc] init];
    }
    return _loginVM;
}

- (void)viewDidLoad {

    [super viewDidLoad];
    //1.给模型的账号&&密码绑定信号!!
    RAC(self.loginVM, account) = _accountFiled.rac_textSignal;
    RAC(self.loginVM, pwd) = _pwdFiled.rac_textSignal;
    //2.设置按钮
    RAC(_loginBtn, enabled) = self.loginVM.loginEnableSignal;
    //3.监听登录按钮的点击
    [[_loginBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl *_Nullable x) {
        //处理登录事件
        [self.loginVM.loginCommand execute:@"账号密码"];
    }];

}


@end
